<?php

//Begin//Xay dung chuoi XML chua gia tri
$v_list_xml_tag = "";
if(isset($_REQUEST['hdn_list_xml_tag'])){
	$v_list_xml_tag = $_REQUEST['hdn_list_xml_tag'];
//	echo $v_list_xml_tag.'<br/>';
}
$v_list_xml_value = "";
if(isset($_REQUEST['hdn_list_xml_value'])){
	$v_list_xml_value = $_REQUEST['hdn_list_xml_value'];
	//$v_list_xml_value = strtoupper($v_list_xml_value);
//	echo $v_list_xml_value.'<br/>';
}

//echo $v_count_filter.'<br/>';
if(isset($_REQUEST['hdn_count_filter'])){
	$v_count_xml = intval($_REQUEST['hdn_count_filter']);
//	echo $v_count_xml.'<br/>';
}	
//echo _CONST_SUB_LIST_DELIMITOR;
$v_xml_str = '<?xml version="1.0" encoding="UTF-8"?><root><data_list>';
for ($i=0; $i<_list_get_len($v_list_xml_tag,_CONST_SUB_LIST_DELIMITOR); $i++){
	$v_xml_str = $v_xml_str ."<"._list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR).">";
	$v_xml_str = $v_xml_str .trim(_replace_XML_bad_char(_list_get_at($v_list_xml_value,$i,_CONST_SUB_LIST_DELIMITOR)));
	$v_xml_str = $v_xml_str ."</"._list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR).">";
}
$v_xml_str = $v_xml_str . "</data_list></root>";

$v_staff_id = intval($_SESSION['staff_id']);
//$v_staff_id = -10;

$v_recordtype_filter = $_SESSION['onegate_current_recordtype'];

//===============================================================================
$v_ho_ten ="";
if(isset($_REQUEST['ho_ten'])&&$_REQUEST['ho_ten']!=''){
	$v_ho_ten=$_REQUEST['ho_ten'];
}
if(isset($_REQUEST['registor_name'])&&$_REQUEST['registor_name']!=''){
	$v_ho_ten=$_REQUEST['registor_name'];
}
if(isset($_REQUEST['user_name'])&&$_REQUEST['user_name']!=''){
	$v_ho_ten=$_REQUEST['user_name'];
}
if(isset($_REQUEST['ho_va_ten'])&&$_REQUEST['ho_va_ten']!=''){
	$v_ho_ten=$_REQUEST['ho_va_ten'];
}
if(isset($_REQUEST['ho_ten_than_nhan'])&&$_REQUEST['ho_ten_than_nhan']!=''){
	$v_ho_ten=$_REQUEST['ho_ten_than_nhan'];
}
//echo '$v_ho_ten='.$v_ho_ten;

//==============================================================================
$v_from_receive_date = "";
if(isset($_REQUEST['from_receive_date'])){
	$v_from_receive_date = _ddmmyyyy_to_yyyymmdd($_REQUEST['from_receive_date']);
}
$v_to_receive_date = "";
if(isset($_REQUEST['to_receive_date'])){
	$v_to_receive_date = _ddmmyyyy_to_yyyymmdd($_REQUEST['to_receive_date']);
}
$v_from_result_date = "";
if(isset($_REQUEST['from_appointed_date'])){
	$v_from_result_date = _ddmmyyyy_to_yyyymmdd($_REQUEST['from_appointed_date']);
}
$v_to_result_date = "";
if(isset($_REQUEST['to_appointed_date'])){
	$v_to_result_date = _ddmmyyyy_to_yyyymmdd($_REQUEST['to_appointed_date']);
}
/*$v_c_code="";
if(isset($_REQUEST['c_code'])){
	$v_c_code =$_REQUEST['c_code'];
}*/
//Leav_29092008
$v_record_code="";
if(isset($_REQUEST['record_id_search'])){
	$v_record_code =$_REQUEST['record_id_search'];
}
//Leav_29092008_end
$v_cmt_num = 0;

//Chi hien thi cac ho so ung voi trang thai la da duoc lanh dao phe duyet "CAP_PHEP" 
$v_status_list = 'CAP_PHEP';
//Lay so dong tren mot danh sach
$v_limit_row = _CONST_NUMBER_OF_ROW_PER_LIST;
if(isset($_REQUEST['hdn_record_number_page'])){
	$v_limit_row = $_REQUEST['hdn_record_number_page'];
}
//Lay trang thu x
$v_page = 1;
if(isset($_REQUEST['hdn_page'])){
	$v_page=$_REQUEST['hdn_page'];
}

/*
$v_filter_value = '';
if(isset($_REQUEST['ho_ten'])){
	//$v_filter_value = $_REQUEST['registor_name'];
	$rax = new RAX(); 
	$rec = new RAX(); 
	$rax->open($v_xml_str);
	$rax->record_delim = "data_list";
	$rax->parse();
	$rec = $rax->readRecord(); 
	$row = $rec->getRow();
	//$v_filter_value = _restore_XML_bad_char($row["registor_name"]);
	$v_filter_value = _restore_XML_bad_char($row["ho_ten"]);
}

$v_cmt_num = 0;
if(isset($_REQUEST['cmnd'])){
	//$v_filter_value = $_REQUEST['registor_name'];
	$rax = new RAX(); 
	$rec = new RAX(); 
	$rax->open($v_xml_str);
	$rax->record_delim = "data_list";
	$rax->parse();
	$rec = $rax->readRecord(); 
	$row = $rec->getRow();
	$v_cmt_num = $row["cmnd"];
}

$v_record_code= '';
if(isset($_REQUEST['record_code'])){
	//$v_record_code = $_REQUEST['record_code'];
	$rax = new RAX(); 
	$rec = new RAX(); 
	$rax->open($v_xml_str);
	$rax->record_delim = "data_list";
	$rax->parse();
	$rec = $rax->readRecord(); 
	$row = $rec->getRow();
	$v_record_code = _restore_XML_bad_char($row["record_code"]);
}

$v_filter_xml_tag = '';
if(isset($_REQUEST['filter_xml_tag'])){
	$v_filter_xml_tag = $_REQUEST['filter_xml_tag'];
}
*/

//echo 'v_xml_str'.htmlspecialchars($v_xml_str); 
if(_is_sqlserver()){
	$v_recordtype_filter_ = $v_recordtype_filter;
	if($v_recordtype_filter=="All")
		for($i=0;$i<sizeof($arr_all_recordtype);$i++)
			if($i==0) $v_recordtype_filter_ = $arr_all_recordtype[$i][0];
			else $v_recordtype_filter_ .= ','.$arr_all_recordtype[$i][0];
	
	if($v_count_xml>0)
	{
		$array_list_xml_value = explode('!~~!',$v_list_xml_value);
		$array_list_xml_tag = explode('!~~!',$v_list_xml_tag);
		$v_list_xml_value_temp = '';
		$v_list_xml_tag_temp = '';

		for($j=0;$j<$v_count_xml;$j++){
			$ho_ten = array('ho_ten','registor_name','user_name','ho_va_ten','ho_va_ten_than_nhan');
			if(in_array($array_list_xml_tag[$j],$ho_ten)==true)
				$v_list_xml_value_temp.= GetStringToSearch($array_list_xml_value[$j]).',';
			else
				$v_list_xml_value_temp.= $array_list_xml_value[$j].',';
				
			$v_list_xml_tag_temp.= $array_list_xml_tag[$j].',';
		}
	
//		$v_list_xml_value = str_replace($v_list_xml_value,$v_list_xml_value_temp,$v_list_xml_value);
//		$v_list_xml_tag = str_replace($v_list_xml_tag,$v_list_xml_tag_temp,$v_list_xml_tag);
	}
	else
		$v_count_xml = 0;			
	//echo "v_list_xml_tag=".$v_list_xml_tag;
	$sql = "Exec Onegate_ArchiveRecordGetPerPage_LeAV_300908";
	$sql = $sql . " " . $v_staff_id ;
	$sql = $sql . ",'" . $v_recordtype_filter_ . "'" ;
	//$sql = $sql . ",'" . $v_c_code . "'" ;
	$sql = $sql . ",'" .$v_from_receive_date. "'" ;
	$sql = $sql . ",'" .$v_to_receive_date. "'" ;
	$sql = $sql . ",'" .$v_from_result_date. "'" ;
	$sql = $sql . ",'" .$v_to_result_date. "'" ;	
//	$sql = $sql . ",'" .$v_filter_value. "'" ;	
//	$sql = $sql . ",'" . $v_filter_xml_tag."'" ;
	$sql = $sql . ",'" .$v_list_xml_value_temp. "'" ;	
	$sql = $sql . ",'" .$v_list_xml_tag_temp. "'" ;
	$sql = $sql.",".$v_page;
	$sql = $sql.",".$v_limit_row;
	$sql = $sql.",'".$v_record_code."'";
	$sql = $sql.",".$v_count_xml;
	
//	echo $sql; //exit;
	
	$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$arr_all_record = $ado_conn->GetAll($sql);
	$v_total_record = $arr_all_record[0]['TOTAL_RECORD'];
}
?>